<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>政府救助帮扶信息页面</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
    <style>
        .discell {
            text-align:right;
            width:15%;
        }
        .input {
            width:20%;
        }
    </style>
</head>
<body>

<form id="form1" class="mini-fit" method="post" style="margin-bottom: 40px;">
    <!-- 用户 编辑框START-->
    <div id="editform" class="form" style="padding:10px;margin-left: -15%;">
        <input id="id" name="id" class="mini-hidden" style="width: 100%;" readonly />
        <input name="createUser" class="mini-hidden" style="width: 100%;" value="${createUser!''}" />
        <input name="adduserid" class="mini-hidden" style="width: 100%;" value="${adduserid!''}" />
        <input name="addusername" class="mini-hidden" style="width: 100%;" value="${addusername!''}" />
        <input name="departid" class="mini-hidden" style="width: 100%;" value="${departid!''}" />
        <table class="form-table" align="center" cellspacing="8">
            <tr>
                <td class="discell"><font color="#dc143c">*</font>帮扶类目:</td>
                <td>
                    <input name="bftype" id="bftype" class="mini-combobox" required="true"
                           textField="codeName" valueField="codeId" emptyText="请选择..."
                           url="/azbj/shzzgl/socialOrgInfo/getComboboxData?codeType=3_2"
                    />
                </td>
            </tr>
            <tr>
                <td class="discell">有效时间:</td>
                <td class="input">
                    <input name="repal_time" id="repal_time" allowInput="false" class="mini-datepicker" format="yyyy-MM-dd" ondrawdate="onDrawDate"/>至<input
                            name="recover_time" id="recover_time" allowInput="false" class="mini-datepicker" ondrawdate="onDrawDate1" format="yyyy-MM-dd" />
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>协调单位:</td>
                <td>
                    <input name="xtdw" id="xtdw" class="mini-textbox" required="true" />
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>
                    协调单位地址:
                </td>
                <td colspan="4" class="input">
                    <input id="bfProvince" name="bfProvince" class="mini-combobox" required="true" emptyText="省份" style="width:150px;"
                           textfield="codeName" valueField="codeId"
                           onclick="onDeptChanged('bfProvince')" onvaluechanged="onValueChanged('bfProvince')" />
                    <input id="bfCity" name="bfCity" class="mini-combobox" required="true" emptyText="市" style="width: 140px"
                           textfield="codeName" valueField="codeId" onclick="onDeptChanged('bfCity')"
                           onvaluechanged="onValueChanged('bfCity')" />
                    <input id="bfCounty" name="bfCounty" class="mini-combobox" required="true" emptyText="县" style="width: 150px"
                           textfield="codeName" valueField="codeId" onclick="onDeptChanged('bfCounty')"
                           onvaluechanged="onValueChanged('bfCounty')" />
                    <input id="bfClab" name="bfClab" class="mini-combobox" required="true" emptyText="街道" style="width: 140px"
                           textfield="codeName" valueField="codeId"onclick="onDeptChanged('bfClab')" />
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>具体帮扶工作:</td>
                <td>
                    <input name="bfwork" id="bfwork" class="mini-textbox" required="true" />
                </td>
            </tr>
            <tr>
                <td class="discell">补贴形式:</td>
                <td>
                    <input name="bttype" id="bttype" class="mini-textbox" />
                </td>
            </tr>
            <tr>
                <td class="discell">补助金额:</td>
                <td>
                    <input name="btje" id="btje" class="mini-spinner" minValue="0" maxValue="200000" emptyText="可滚动鼠标滚轮调整" />
                </td>
            </tr>
        </table>
    </div>
</form>
<div style="width:100%; position: absolute;bottom: 0;line-height:40px;border-top: 1px solid #dfdfdf;text-align: center;">
    <#if flog!='1'>
        <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()">保存</a>
    </#if>
    <a class="mini-button" iconCls="fa-undo" plain="true" onclick="onCancel()">取消</a>
</div>

<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");
    var repal_time = mini.get("repal_time");
    var recover_time = mini.get("recover_time");
    var createUser = mini.getByName("createUser").getValue();
    var adduserid = mini.getByName("adduserid").getValue();
    var addusername = mini.getByName("addusername").getValue();
    var bfProvince= mini.get("bfProvince");
    var bfCity = mini.get("bfCity");
    var bfCounty = mini.get("bfCounty");
    var bfClab = mini.get("bfClab");
    var departid = mini.getByName("departid").getValue();


    $(document).ready(function () {
        addressLocking();
    });

    //地址锁定
    function addressLocking(){
        $.ajax({
            url: "/azbj/getAddressLocking",
            type: "GET",
            success: function (res) {
                if(res.level == "06" || res.level == "07" || res.level == "08" || res.level == "03"){
                    bfProvince.setData([{"codeId": res.shengCode, "codeName": res.shengName}]);
                    bfProvince.setValue(res.shengCode);
                    bfProvince.setEnabled(false);
                }
                if(res.level == "07" || res.level == "08" || res.level == "03"){
                    bfCity.setData([{"codeId": res.dishiCode, "codeName": res.dishiName}]);
                    bfCity.setValue(res.dishiCode);
                    bfCity.setEnabled(false);
                }
                if(res.level == "08" || res.level == "03"){
                    bfCounty.setData([{"codeId": res.quxianCode, "codeName": res.quxianName}]);
                    bfCounty.setValue(res.quxianCode);
                    bfCounty.setEnabled(false);
                }
                if(res.level == "03"){
                    bfClab.setData([{"codeId": res.jiedaoCode, "codeName": res.jiedaoName}]);
                    bfClab.setValue(res.jiedaoCode);
                    bfClab.setEnabled(false);
                }
            }
        });
    }

    //标准方法接口定义
    function SetData(data) {
        if (${flog!''} != 1 && !check(data.btje)) {
            mini.alert("您之前录入的补助金额为:【" + data.btje + "】,不是数字,请重新设置并保存！");
        }
        if (data.id) {
            mini.get("id").setEnabled(false);
        }
        var o = mini.decode(data);
        form.setData(o);
        if (${flog!''} == 1) {
            form.setEnabled(false);
        }
        //设置有效时间回显
        repal_time.setValue(data.repalTime);
        recover_time.setValue(data.recoverTime);
        //设置省市县回显
        bfProvince.setData([{"codeId": data.bfProvince, "codeName": data.bfprovinceName}]);
        bfCity.setData([{"codeId": data.bfCity, "codeName": data.bfcityName}]);
        bfCounty.setData([{"codeId": data.bfCounty, "codeName": data.bfcountyName}]);
        bfClab.setData([{"codeId": data.bfClab, "codeName": data.bfclabName}]);
        form.setChanged(false);
    }

    //校验数字(带小数点)
    function check(e) {
        var re = /^[1-9][0-9]*([.][0-9]{1,2})?$/;
        if (e != "" && e != undefined && e != 0) {
            if (!re.test(e)) {
                return false;
            }
            return true;
        }
        return true;
    }

    function saveData() {
        form.validate();
        if (form.isValid() == false || ${flog!''} == 1) {
            return;
        }
        var data = form.getData();
        //有效时间开始不能大于有效时间结束
        if (data.repal_time != 0 && data.recover_time != 0 && data.repal_time > data.recover_time) {
            mini.alert("有效时间开始不能大于有效时间结束");
            return;
        }
        //验证补助金额
        if (data.btje) {
            var btJeValResult = onJeValidation(data.btje);
            if (btJeValResult == false) {
                mini.alert("补助金额格式不正确!")
                return;
            }
        }
        //保存创建用户、录入单位、录入单位名称信息
        data.createUser = createUser;
        data.adduserid = adduserid;
        data.addusername = addusername;
        data.clab = departid;
        var json = mini.encode(data);
        commonSaveData("/azbj/zfjzbf/baseinfo/save", {data: json}, callback);
        // 保存成功的回调函数
        function callback() {
            mini.alert("保存成功", "成功", window.CloseOwnerWindow);
        }
    }

    function onJeValidation(num) {
        //验证是数字或者两位小数，或者一位小数
        var btje = /^\d+(\.\d{1,2})?$/;
        if (btje.test(num)) {
            return true;
        } else {
            return false;
        }
    }

    var urltemp = "/azbj/getCodeDetail/?codeType=2_1&codeId=-2";
    function onDeptChanged(e) {

        if ("bfProvince" == e) {
            var value = bfProvince.getValue();
            bfProvince.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=-1";
            bfProvince.setUrl(url);
            if (value != '') {
                bfProvince.setValue(value);
            } else {
                bfProvince.select(0);
            }
        }
        if ("bfCity" == e) {
            var value = bfCity.getValue();
            if (bfProvince.getValue() == "") {
                bfProvince.setUrl(urltemp);
                bfProvince.setValue("");
                bfCounty.setUrl(urltemp);
                bfCounty.setValue("");
                bfClab.setUrl(urltemp);
                bfClab.setValue("");
                return;
            }
            var codeId = bfProvince.getValue();
            bfCity.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            bfCity.setUrl(url);
            if (value != '') {
                bfCity.setValue(value);
            } else {
                bfCity.select(0);
            }
        }
        if ("bfCounty" == e) {
            var value = bfCounty.getValue();

            if (bfCity.getValue() == "") {
                bfCounty.setUrl(urltemp);
                bfCounty.setValue("");
                bfClab.setUrl(urltemp);
                bfClab.setValue("");
                return;
            }
            var codeId = bfCity.getValue();
            bfCounty.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            bfCounty.setUrl(url);
            if (value != '') {
                bfCounty.setValue(value);
            } else {
                bfCounty.select(0);
            }
        }
        if ("bfClab" == e) {
            var value = bfClab.getValue();
            if (bfCounty.getValue() == "") {
                bfClab.setUrl(urltemp);
                bfClab.setValue("");
                return;
            }
            var parent_code = bfCounty.getValue();
            bfClab.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + parent_code;
            bfClab.setUrl(url);
            if (value != '') {
                bfClab.setValue(value);
            } else {
                bfClab.select(0);
            }
        }
    }

    function onValueChanged(e) {
        if ("bfProvince" == e) {
            bfCity.setValue("");
            bfCounty.setValue("");
            bfClab.setValue("");
        }
        if ("bfCity" == e) {
            bfCounty.setValue("");
            bfClab.setValue("");
        }
        if ("bfCounty" == e) {
            bfClab.setValue("");
        }
    }

    /**
     * 禁止选择今天之前的日期
     * @param e
     */
    function onDrawDate1(e) {
        var date = e.date;
        var d = new Date();
        //一天等于86400000ms
        if (d.getTime()-86400000 > date.getTime()) {
            e.allowSelect = false;
        }
    }
    function onDrawDate(e) {
        var date = e.date;
        var d = new Date();
        if (date.getTime() > d.getTime()) {
            e.allowSelect = false;
        }
    }


</script>
</body>
</html>